




/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：02/08/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/ 
package com.application.yfthesis.struts.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.application.yfthesis.commons.Constants;
import com.application.yfthesis.entity.YfThesis;
import com.application.yfthesis.service.YfThesisService;
import com.application.yfthesis.struts.form.YfThesisForm;
import com.manager.commons.CommonUtil;
import com.manager.commons.RandomKey;
import com.manager.commons.page.PageBean;
import com.manager.workflow.WorkFlowConstants;
 /**
 * 
 * Description:YfThesisAction<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060    <br />
 * 
 * History: <br />
 * 
 * 02/08/2012 
 * 
 */
public class YfThesisAction extends DispatchAction
{
       
       /**
	 * Service层实例
	 */
	private YfThesisService yfThesisService;

	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * 实体对象
	 */
        private YfThesis yfThesis;


        /**
	 * 采用partialList方式分页程序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward getYfThesisPartialList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("searchYfThesis" + "开始");
		YfThesisForm yfThesis = (YfThesisForm)form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List yfThesisList = null;
		resultSize = yfThesisService.getAllCountYfThesis(yfThesis);
		pageBean = PageBean.getPageBean("yfThesisTab", resultSize,request);
		yfThesisList = yfThesisService.searchYfThesis(yfThesis,pageBean);
		request.setAttribute("yfThesisList", yfThesisList);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		log.debug("searchYfThesis" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}

        /**
	 * 到达新增页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toAddYfThesis(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toAddYfThesiss");
		YfThesisForm yfThesisForm = (YfThesisForm) form;
		yfThesisForm.setId(RandomKey.generateID_Long_19());
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 增加
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward addYfThesis(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("addYfThesiss");
		YfThesis yfThesis = this.getYfThesis(form);
//                yfThesis.setId(RandomKey.generateID_Long_19());
		 yfThesis.setOperateid(CommonUtil.getCurrentUser(request).getId());
		 yfThesis.setCreateDate(new Date());
		 yfThesis.setStatus(WorkFlowConstants.LW_STATUS_2);
		this.yfThesisService.insertObject(yfThesis);

		return mapping.findForward(Constants.SUCCESS);
	}
        
	/**
	 * 删除
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward deleteYfThesis(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("deleteYfThesiss");
		YfThesisForm yfThesisForm = (YfThesisForm) form;
		this.yfThesisService.deleteYfThesiss(yfThesisForm);
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toUpdateYfThesis(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toUpdateYfThesiss");
		YfThesisForm yfThesisForm = (YfThesisForm) form;
		yfThesis = (YfThesis) this.yfThesisService.searchYfThesis(yfThesisForm,null).get(0);
		request.setAttribute(Constants.YFTHESIS, yfThesis);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		return mapping.findForward(Constants.SUCCESS);
	}

        
	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updateYfThesis(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("updateYfThesiss");
		YfThesis yfThesis = this.getYfThesis(form);
	        yfThesis.setOperateid(CommonUtil.getCurrentUser(request).getId());
		 yfThesis.setCreateDate(new Date());
		this.yfThesisService.updateObject(yfThesis);

		return mapping.findForward(Constants.SUCCESS);
	}
        
	/**
	 * 查看页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward viewYfThesis(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("viewYfThesis");
		YfThesisForm yfThesisForm = (YfThesisForm) form;
		yfThesis = (YfThesis) this.yfThesisService.searchYfThesis(yfThesisForm,null).get(0);
		request.setAttribute(Constants.YFTHESIS, yfThesis);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 审核页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toAuditThesis(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("toAuditThesis");
		YfThesisForm yfThesisForm = (YfThesisForm) form;
		yfThesis = (YfThesis) this.yfThesisService.searchYfThesis(yfThesisForm,null).get(0);
		request.setAttribute(Constants.YFTHESIS, yfThesis);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		return mapping.findForward(Constants.SUCCESS);
	}

	public ActionForward auditYfThesis(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("auditYfThesis");
		YfThesis yfThesis = this.getYfThesis(form);
		YfThesis old = yfThesisService.getYfThesis(yfThesis);
		old.setStatus(yfThesis.getStatus());
		this.yfThesisService.updateObject(old);

		return mapping.findForward(Constants.SUCCESS);
	}
	
	// get--set
	/**
	 * @return the YfThesisService
	 */
	public YfThesisService getYfThesisService() {
		return this.yfThesisService;
	}

	/**
	 * @param YfThesisService
	 *  the YfThesisService to set
	 */
	public void setYfThesisService(YfThesisService yfThesisService) {
		this.yfThesisService = yfThesisService;
	}

	/**
	 * 获取YfThesis实体
	 * @param ActionForm
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @return the YfThesis
	 */
	public YfThesis getYfThesis(ActionForm form) throws IllegalAccessException, InvocationTargetException {
		YfThesisForm yfThesisForm = (YfThesisForm) form;
		yfThesis = new YfThesis();
		BeanUtils.copyProperties(yfThesis, yfThesisForm);
		return yfThesis;
	}
    
        public void setYfThesis(YfThesis yfThesis) {
		this.yfThesis = yfThesis;
	}

}
